<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <link rel="stylesheet" href="static/css/login.css">
</head>
<body>

<div id="login_box">
    <h2>LOGIN</h2>
    <div id="input_box">
        <input type="text" placeholder="请输入用户名" id="name" name="name" required>
    </div>
    <div class="input_box" style="margin-top: 12px">
        <input type="password" placeholder="请输入密码" id="password" name="pwd" required>
    </div>
    <button class="but" id="login_but">登录</button><br>
    <a href="/register" class="but1">注册</a><br>
</div>
<script>

    $(document).ready(function () {
        $("#login_but").on("click",function () {
            $.ajax({
                url:"/login",
                type:"post",
                dataType:"json",
                data:{
                    name:$("#name").val(),
                    password:$("#password").val(),
                },
                success:function (data) {
                    alert(data.data)
                    if(data.data == "登录成功!"){
                        window.location.replace("/index")
                    }
                },
                error:function () {
                    alert("账号或者密码错误！")
                }
            })
        })
    })
</script>


</body>
</html>